import {
  getMoniteSessions, getMoniteStudentsInfo, onStartScore, onFinishScore, getMoniteBaseInfo
} from '@/api/kcjk/index'
import html2canvas from 'html2canvas'
import printJS from 'print-js'
import { mapGetters } from 'vuex'


export default {
  name: 'ksgl-jbxx',
  computed: {
    ...mapGetters(['kcJky'])
  },
  data() {
    return {
      tableData: [],
      listLoading: false,
      formVisible: false,
      fromData: [],
      lie: 0,
      printObj: {
        id: 'printMe',//打印标签的id
        popTitle: ''// 打印的标题，因为css中写了去掉页眉页脚所以不显示
      },
      PrintVisible: false,
      ccmc: ''
    }
  },
  created() {
    this.ccmc = this.$route.query.ccmc
    this.initData(this.$route.query.ccdm)
    // this.getBaseInfo()
  },
  methods: {
    /*getBaseInfo () {
      getMoniteBaseInfo().then(res => {
        this.baseInfo = res.Response
      })
    },*/
    handlePrint() {
      /*printJS({
        printable: 'printMe', // 'printFrom', // 标签元素id
        type: 'html',
        targetStyles: ['*'],
        style: '@page {size : landscape}, @media print { .page { width: 210mm; margin: auto; } }'
      })*/
    },
    onPrintShow () {
      this.PrintVisible = true
      /*console.log(this.$refs.printMe.$refs.DFTable, 'this.$refs.printMe')
      this.$nextTick(() => {
        const printForm = this.$refs.printMe.$refs.DFTable
        const printStr = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>"
        const printPart1 = printStr + '</body></html>'
        const printPart = printPart1 + printForm
        const newTab = window.open('_blank')
        newTab.document.body.innerHTML = printPart
        newTab.print()
        newTab.close()
      })*/
    },
    onPrint () {
      // this.$print(this.$refs.printMe)
      const tabStyle = `<style>
          #printMe{
            color: #999;
          }
          .p-title{
          display: flex;
          justify-content: center;
          font-size: 30px;
          font-family: 新宋体;
          font-weight: bolder;
          letter-spacing: 8px;
          text-align: center;
          }
          table {
            border-top: 1px solid #999;
            border-left: 1px solid #999;
            border-spacing: 0;
            flex: 1;
          }
          tr{
            height: 40px;
          }
          th{
           word-break: break-all;
            padding: 10px;
            border-bottom: 1px solid #999;
            border-right: 1px solid #999;
            height: 50px;
            font-size: 16px;
            text-align: center;
          }
          td {
            word-break: break-all;
            padding: 10px;
            border-bottom: 1px solid #999;
            border-right: 1px solid #999;
            /*min-width: 58px;*/
            height: 17px;
            font-size: 13px;
            text-align: center;
          }
           td .s-text{
            display: inline-block;
            width: 28px;
            text-align: center;
            font-size: 16px;
            }
           td .s-text.s-end{
              width: 70px;
            }
            td.beizhu{
            height: 120px;
            }
          </style><body>`
      this.$nextTick(() => {
        const printForm = this.$refs.printMe.innerHTML
        const printStr = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>"
        const printPart1 = printStr + tabStyle + '</body></html>'
        const printPart = printPart1 + printForm
        const newTab = window.open('_blank')
        newTab.document.body.innerHTML = printPart
        newTab.print()
        newTab.close()
      })
    },
    search() {
      this.initData(this.$route.query.ccdm)
    },
    reset() {
      this.search()
    },
    initData(ccdm) {
      // this.listLoading = true
      getMoniteStudentsInfo({ccdm: ccdm, wcbj: 1}).then(res => {
        this.tableData = res.Response
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
      })
    },
    getCelList (data, list) {
      for (let i = 0; i < data.length; i++) {
        let bl = false
        // console.log(data, list)
        if (list.length === 0) {
          bl = true
          list.push(
            {
              hang: data[i].hang,
              nodes:  [data[i]]
            }
          )
        } else {
          for (let j = 0; j < list.length; j++) {
            if (list[j].hang === data[i].hang) {
              if (list[j].nodes) {
                bl = true
                list[j].nodes.push(data[i])
              }
            }
          }
        }
        if (!bl) {
          list.push(
            {
              hang: data[i].hang,
              nodes:  [data[i]]
            }
          )
        }
      }
    },
    handleAddEdit() {
      this.$router.back()
    },
    removeForm(isRefresh) {
      this.formVisible = false
      if (isRefresh) {
        this.initData()
      }
    }
  }
}
